package su.myspringapps.online_school_learning_spring_data_jpa.repository.main_db;

import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;
import su.myspringapps.online_school_learning_spring_data_jpa.entity.Teacher;

import java.util.List;

/**
 * Интерфейс TeacherRepository
 * <p/>
 * Отвечает за работу с БД, связанную с сущностью {@link Teacher}
 * В учебных целях служит для изучения использования нативных SQL-запросов
 * <p/>
 *
 * @author petr.mikhailin
 * created 16.06.2024 13:08
 */
@Repository
public interface TeacherRepository extends org.springframework.data.repository.Repository<Teacher, Integer> {

    @Query(value = "SELECT * FROM public.teachers", nativeQuery = true)
    List<Teacher> geMeAllTeachers();

    @Query(value = "SELECT * FROM public.teachers WHERE id=?1", nativeQuery = true)
    Teacher giveMeTeacherById(Integer id);

    @Query(value = "SELECT * FROM public.teachers WHERE name=?1 AND age=?2", nativeQuery = true)
    Teacher giveMeTeacherByNameAndAge(String name, Integer age);

    @Query(value = "SELECT * FROM public.teachers WHERE name= :name AND age= :age", nativeQuery = true)
    Teacher giveMeTeacherByNameAndAgeUsingParam(@Param("name") String name, @Param("age") Integer age);

}
